var express = require('express');
var router = express.Router();
const tokenTools = require("../tools/token"); //引入数据库封装模块

const userController = require('../controllers/admin/userController')
const fontEndQuestionController = require('../controllers/admin/fontEndQuestion')


try{
  router.post('/api/adminApi/user/searchUser', tokenTools.authenticate, userController.searchUser)
  router.post('/api/adminApi/user/addUser', tokenTools.authenticate, userController.addUser)
  router.post('/api/adminApi/user/delUser', tokenTools.authenticate, userController.delUser)
  router.post('/api/adminApi/user/updateUser', tokenTools.authenticate, userController.updateUser)
  router.post('/api/adminApi/user/loginChecked', userController.loginChecked)
  router.post('/api/adminApi/user/updateUserInfo', tokenTools.authenticate, userController.updateUserInfo)

  router.post('/api/adminApi/FrontEndQuestions/refresh', userController.refresh)

  router.post('/api/adminApi/FrontEndQuestions/searchFrontEndQuestions', tokenTools.authenticate, fontEndQuestionController.searchFrontEndQuestions)
  router.post('/api/adminApi/FrontEndQuestions/addFrontEndQuestions', tokenTools.authenticate, fontEndQuestionController.addFrontEndQuestions)
  router.post('/api/adminApi/FrontEndQuestions/delFrontEndQuestions', tokenTools.authenticate, fontEndQuestionController.delFrontEndQuestions)
  router.post('/api/adminApi/FrontEndQuestions/updateFrontEndQuestions', tokenTools.authenticate, fontEndQuestionController.updateFrontEndQuestions)
  router.post('/api/adminApi/FrontEndQuestions/getAllType', tokenTools.authenticate, fontEndQuestionController.getAllType)
}catch(err){
  res.send({
      code: '400',
      Msg: '系统错误'
  })
}

/* GET home page. */
/**
 * @swagger
 * /:
 *  get:
 *   tags:
 *     - pet
 *   description: Multiple name values can be provided with comma separated strings
 *   parameters:
 *     - name: name
 *       in: query
 *       description: name values that need to be considered for filter
 *       required: false
 *   responses:
 *     '200':
 *       description: successful operation
 *     '400':
 *       description: Invalid name value
 */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

// 将JWT验证中间件应用到受保护的路由
router.use(tokenTools.authenticate);

module.exports = router;
